<?php
class banco extends CI_Controller {
	var $titp='Banco';
	var $url ='banco/';

	function index(){
		redirect($this->url.'filteredgrid');
	}

	function filteredgrid(){
		$this->load->library('rapyd');

		$filter = new datafilter_library();
		$filter->label = 'Características de la cuenta';
		$sel=array('banco.id AS id','tban.nombre AS tbnombre','banco.contacto AS contacto','banco.cuenta AS cuenta','banco.saldo AS saldo');
		$filter->db->select($sel);
		$filter->db->from('banco');
		$filter->db->join('tban','banco.id_ban=tban.id');

               // $filter->field('input','tban.nombre','Nombre del banco')->attributes(array('style' => 'width:170px'));	
	
		$filter->field('dropdown','id_ban','Nombre del banco')
			->option('','Seleccionar')
			->options('SELECT id,nombre FROM tban ORDER BY nombre')
			->attributes(array('style'   => 'width: 200px'))
			->rule('trim|required');


		$filter->buttons('reset', 'search');
		$filter->build();

		$uri = anchor($this->url.'dataedit/show/<raencode><#id#></raencode>','<#id#>');

		$grid = new datagrid_library();

		$grid->label = 'Lista de las cuentas';
		$grid->per_page = 40;
		$grid->cid = '';
		$grid->source($filter);

		
		$grid->column('tbnombre','Banco',true)->url($this->url.'dataedit/show/{id}');

            	$grid->column('contacto','Contacto');
                $grid->column('cuenta','Cuenta');
                $grid->column('saldo','Saldo');

		$grid->add_button(array('url'=>$this->url.'dataedit/create'));
		$action = "javascript:window.location.href='".site_url('/')."'";
		$grid->button('btn_reg', 'Regresar', $action, 'TR');
		$grid->build();

		$data['content'] = $filter->output.$grid->output;
		$data['head']    = $this->rapyd->head().script('jquery.js');
		$data['title']   = '';
		$this->load->view('view_ventanas_sola', $data);

	}

	function dataedit(){
		$this->load->library('rapyd');

		$edit = new dataedit_library();
		$edit->label = 'Banco';
		$edit->back_url = site_url($this->url.'filteredgrid');

		$edit->source('banco');
		
		$edit->field('dropdown','id_ban','Banco')
			->option('','Seleccionar')
			->options('SELECT id,nombre FROM tban ORDER BY nombre')
			->attributes(array('style'   => 'width: 200px'))
			->rule('trim|required');

		$edit->field('input','contacto','Contacto')
			->rule('trim|required');

		
                $edit->field('input','cuenta','Cuenta')
		     ->rule('trim|unique|required');

			      
                $edit->field('input','saldo','Saldo')
		     ->rule('numeric|required');

		$edit->buttons('modify','save','undo','delete','back');

		$edit->build();

		$data['head']    = $this->rapyd->head();
		$data['content'] = $edit;
		$this->load->view('view_ventanas_sola', $data);




	}

	
}

